<template>
  <el-card style="max-width: 480px">
    <template #header>
      <div class="card-header">
        <span>修改密码</span>
      </div>
    </template>

    <el-form :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="原密码">
        <el-input type="password" v-model="form.old_pwd"/>
      </el-form-item>

      <el-form-item label="新密码">
        <el-input type="password" v-model="form.new_pwd"/>
      </el-form-item>
      <el-form-item label="确认密码">
        <el-input type="password" v-model="form.re_pwd"/>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
        <!--        <el-button>保存</el-button>-->
      </el-form-item>
    </el-form>


  </el-card>
</template>
<script lang="ts" setup>
import {onMounted, reactive, ref} from 'vue'
import {showTips, successTips, warningTips} from "@/utils/util";

import {getEnterpriseInfoApi, updateMyInfoApi, updatePwdApi} from "@/api/enterprise";

// do not use same name with ref
const form = reactive(
    {
      old_pwd: "",
      new_pwd: "",
      re_pwd: ""
    }
)

const onSubmit = () => {
  updatePwdApi(form).then((response: any) => {
    if (response.code === 200) {
      Object.assign(form, {
        old_pwd: "",
        new_pwd: "",
        re_pwd: ""
      })
      successTips(response.message)
    } else {
      warningTips(response.message)
    }
  })
}


</script>
